#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "sorts.h"
 
typedef void (*lpfn_sort_t)(ELE_TYPE arr[], int len);
 
extern void test_bubble_sort();
extern void test_select_sort();
extern void test_insert_sort();
extern void test_shell_sort();
extern void test_quick_sort();
extern void test_merge_sort();
extern void test_heap_sort();
 
void perf_test(ELE_TYPE *arr, int len, lpfn_sort_t fun, const char *fun_name )
{
	uint64_t start,end;
 
	start=getCurrentTimeMsec();
	fun(arr,len);
	end=getCurrentTimeMsec();
	printf("Did %s on %d elements spend %d ms\n", fun_name,len, (unsigned)(end-start));
}
 
void all_sort_fun_perf_test()
{
	ELE_TYPE *src=NULL;
	ELE_TYPE *arr=NULL;
	int i;
 
	src=(ELE_TYPE*)malloc(MAX_LEN*sizeof(ELE_TYPE));
	arr=(ELE_TYPE*)malloc(MAX_LEN*sizeof(ELE_TYPE));
 
	srand(time(NULL));
	for (i=0;i<MAX_LEN;i++)
		src[i]=rand() % MAX_LEN;
 
	memcpy(arr,src,sizeof(ELE_TYPE)*MAX_LEN);
	perf_test(arr, MAX_LEN, shell_sort, "shell sort" );
 
	memcpy(arr,src,sizeof(ELE_TYPE)*MAX_LEN);
	perf_test(arr, MAX_LEN, merge_sort, "merge sort" );
 
	memcpy(arr,src,sizeof(ELE_TYPE)*MAX_LEN);
	perf_test(arr, MAX_LEN, quick_sort, "quick sort" );
 
	memcpy(arr, src, sizeof(ELE_TYPE)*MAX_LEN);
	perf_test(arr, MAX_LEN, heap_sort, "heap sort");
 
	free(src); src=NULL;
	free(arr); arr=NULL;
}
 
 
int main(int argc, char* argv[])
{
	printf("------------------------\n");
	all_sort_fun_perf_test();
	return 0;
}
 
